package com.iis.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Properties;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;

import org.jdatepicker.impl.JDatePanelImpl;
import org.jdatepicker.impl.JDatePickerImpl;
import org.jdatepicker.impl.UtilDateModel;

import com.iis.entity.Admin;
import com.iis.entity.Agent;
import com.iis.entity.Salesman;

public class EditStaffForm extends JFrame {
	
	private static EditStaffForm frame;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					JTable dataTable = new JTable();
					frame = new EditStaffForm(dataTable);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public EditStaffForm(JTable dataTable) {
		
		this.setTitle("Add New Staff");
		InitializeForm(null);
		
		
	}
	
	public EditStaffForm(JTable dataTable, Salesman staff) {
		this.setTitle("Edit Existing Staff");
		InitializeForm(staff);
		
	}
	
	public void InitializeForm(Salesman staff){
		JPanel contentPane = new JPanel();
		contentPane.setLayout(null);
		contentPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
		
		JLabel lblID = new JLabel("Employee No");
		lblID.setFont(lblID.getFont().deriveFont(12.0f));
		lblID.setBounds(40, 40, 100, 30);
		
		JLabel lblName = new JLabel("Name");
		lblName.setFont(lblID.getFont());
		lblName.setBounds(40, 80, 100, 30);
		
		JLabel lblTarget = new JLabel("Target Sales");
		lblTarget.setFont(lblID.getFont());
		lblTarget.setBounds(40, 120, 100, 30);
		
		JTextField idTF = new JTextField();
		if(staff != null) idTF.setText(staff.getEmployeeNo());
		idTF.setColumns(20);
		idTF.setFont(idTF.getFont().deriveFont(14.0f));
		idTF.setBounds(190, 40, 220, 30);
		
		JTextField nameTF = new JTextField();
		if(staff != null) nameTF.setText(staff.getName());
		nameTF.setColumns(20);
		nameTF.setFont(idTF.getFont());
		nameTF.setBounds(190, 80, 220, 30);
		
		JTextField targetTF = new JTextField();
		if(staff != null) targetTF.setText(staff.getSalesTarget().toString());
		targetTF.setColumns(20);
		targetTF.setFont(idTF.getFont());
		targetTF.setBounds(190, 120, 220, 30);
		
		contentPane.add(lblID);
		contentPane.add(idTF);
		
		contentPane.add(lblName);
		contentPane.add(nameTF);
		
		contentPane.add(lblTarget);
		contentPane.add(targetTF);
		
		JButton btnSubmit = new JButton("Submit");
		btnSubmit.setBounds(190, 160, 100, 40);
		contentPane.add(btnSubmit);
		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.setBounds(310, 160, 100, 40);
		contentPane.add(btnCancel);
		
		setContentPane(contentPane);
		
		getContentPane().setLayout(null);
		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		setBounds(100, 100, 500, 280);
		
		frame = this;
		
		btnSubmit.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				
				
			}
		});
		
		btnCancel.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				frame.setVisible(false);
			}
		});
	}
}